<?php
define('API_USER_URL', 'http://www.huimin99.cn/api/user.php');
define('API_SMS_URL', 'http://www.huimin99.cn/api/sms.php');

/*
* 获取用户信息
*/
function api_user_info($field, $value)
{
	$url = API_USER_URL . '?action=info&'.$field.'='.$value;
	$json = http_get($url);
	return json_decode($json, true);
}
/*
* 添加用户
*/
function api_user_add($mobile, $password)
{
	$url = API_USER_URL . '?action=add&mobile='.$mobile.'&password='.$password;
	$json = http_get($url);
	return json_decode($json, true);
}
/*
* 获到购物券记录
*/
function api_user_points_logs($user_id, $type, $offset=0, $pagesize=20, $start=0, $end=0, $orderby_type=0)
{
	$url = API_USER_URL . '?action=points_log&user_id='.$user_id.'&type='.$type.'&offset='.$offset.'&pagesize='.$pagesize.'&start='.$start.'&end='.$end.'&orderby_type='.$orderby_type;
	$json = http_get($url);
	return json_decode($json, true);
}

/*
* 批量获取购物券
*/
function api_batch_points($user_ids)
{
	$url = API_USER_URL . '?action=batch_points';
	foreach($user_ids as $user_id) $url .= "&user_ids[]=".$user_id;
	$json = json_decode(http_get($url), true);
	$data = array();
	foreach($json['data'] as $val) $data[$val['user_id']] = $val['pay_points'];
	return $data;
}
/*
* 发送手机短信
*/
function api_send_sms($mobile, $parm, $tid)
{
	$url = API_SMS_URL . '?action=send&mobile='.$mobile.'&parm='.urlencode(json_encode($parm)).'&tid='.$tid;
	$json = http_get($url);
	return json_decode($json, true);
}

/*
* 账户变动 $type 1购买商品 2上级分配 3下级充值 4商城调整
*/
function api_account_change($mobile, $pay_points = 0, $type=2, $change_desc = '')
{
	$url = API_USER_URL . '?action=account_change&mobile='.$mobile.'&pay_points='.$pay_points.'&operator_id='.$_SESSION['user_id'].'&type='.$type.'&change_desc='.urlencode($change_desc);
	$json = http_get($url);
	return json_decode($json, true);
}